package com.itheima.wms.controller;

import com.itheima.wms.pojo.Location;
import com.itheima.wms.pojo.LocationDto;
import com.itheima.wms.pojo.LocationPageQueryVo;
import com.itheima.wms.pojo.LocationVO;
import com.itheima.wms.service.LocationService;
import com.itheima.wms.utils.PageBean;
import com.itheima.wms.utils.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequiredArgsConstructor
@RestController
@RequestMapping("/location")
public class LocationController {

    private final LocationService locationService;

    @GetMapping("/pageDetail")
    public Result queryLocationPageByCondition(LocationPageQueryVo locationPageQueryVo) {
        PageBean<Location> pageBean = locationService.queryLocationPageByCondition(locationPageQueryVo);
        return Result.success(pageBean);
    }

    @PostMapping
    public Result addLocation(@RequestBody Location location) {
        locationService.insertLocation(location);
        return Result.success("插入成功");
    }

    @GetMapping("/{id}")
    public Result queryLocationById(@PathVariable("id") Long id) {
        Location location = locationService.queryLocationById(id);
        return Result.success(location);
    }

    @DeleteMapping
    public Result<String> delete(@RequestParam("ids[]") List<Long> ids) {
        Long id = ids.get(0);
        locationService.delete(id);
        return Result.success("操作成功");
    }

    @PutMapping
    public Result update(@RequestBody Location location) {
        locationService.update(location);
        return Result.success("修改成功");
    }

    @GetMapping("/listDetail")
    public Result LocationDetail(LocationDto locationDto) {
        List<LocationVO> locationVOList = locationService.locationDetail(locationDto);
        return Result.success(locationVOList);
    }
}
